package com.java.tutorials.jdk7.fileattribute;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.attribute.UserPrincipalLookupService;
/**
 * Created by xuzhike on 2016/1/24.
 * http://www.java2s.com/Code/Java/JDK-7/SettingOwner.htm
 */
public class SettingOwnerTest {
    public static void main(String[] args) throws Exception {
        Path path = Paths.get("e:/yjbWechat.txt");
        FileOwnerAttributeView view = Files.getFileAttributeView(path,
                FileOwnerAttributeView.class);
        UserPrincipalLookupService lookupService = FileSystems.getDefault()
                .getUserPrincipalLookupService();
        UserPrincipal userPrincipal = lookupService.lookupPrincipalByName("mary");

        view.setOwner(userPrincipal);
        System.out.println("Owner: " + view.getOwner().getName());
    }
}
